package com.heny.demo.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @author yaonn
 * @date 2025/9/1123:32
 * @Description
 */
@Component
public class FileImportStrategyFactory {
    private final List<FileImportStrategy> strategies;

    @Autowired
    public FileImportStrategyFactory(List<FileImportStrategy> strategies) {
        this.strategies = strategies;
    }
    public FileImportStrategy getStrategy(String fileType) {
        return strategies.stream()
                .filter(s -> s.supports(fileType))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("不支持的文件类型: " + fileType));
    }
}
